package com.jcsz.gulimall.search.controller;

/**
 * @className: ProductSaveController
 * @author: 一把Po吉他
 * @date: 2022/10/30 18:40
 * @version: 1.0
 **/

import com.jcsz.common.exception.BizCodeEnume;
import com.jcsz.common.to.es.SkuEsModel;
import com.jcsz.common.utils.R;
import com.jcsz.gulimall.search.service.ProductSaveService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * es保存
 */
@Slf4j
@RequestMapping("/search/save")
@RestController
public class ProductSaveController {
    @Autowired
    ProductSaveService productSaveService;

    @PostMapping("product")
    public R productStatusUp(@RequestBody List<SkuEsModel> skuEsModels) {
        Boolean result = false;
        try {
            result = productSaveService.productStatusUp(skuEsModels);
        } catch (Exception exception) {
            return R.error(BizCodeEnume.PRODUCT_UP_EXCEPTION.getCode(),BizCodeEnume.PRODUCT_UP_EXCEPTION.getMsg() );
        }
        if (result) {
            return R.ok();
        }else {
            return R.error(BizCodeEnume.PRODUCT_UP_EXCEPTION.getCode(),BizCodeEnume.PRODUCT_UP_EXCEPTION.getMsg() );
        }
    }


}
